#include "levitationbutton.h"
#include <QPainter>
#include <QStyleOption>
#include <QBitmap>
#include <QHBoxLayout>

const int WIN_W = 126;
const int WIN_H = 48;
const int ICON_W = 16;
const int ICON_H = 16;

LevitationButton::LevitationButton(QWidget *parent) : QPushButton(parent)
{
    setFixedSize(WIN_W, WIN_H);
    setAttribute(Qt::WA_TranslucentBackground, true);
    setWindowFlags(Qt::FramelessWindowHint);
    m_icon = new QLabel(this);
    m_icon->setFixedSize(ICON_W, ICON_H);
    m_text = new QLabel(this);
    m_text->setStyleSheet("color:#FFFFFF;text-align:center;");

    QHBoxLayout *layout = new QHBoxLayout;
    layout->setSpacing(0);
    layout->setMargin(0);
    layout->addWidget(m_icon);
    layout->addSpacing(8);
    layout->addWidget(m_text);
    layout->setContentsMargins(16, 16, 16, 16);
    setLayout(layout);

    setStyleSheet("QPushButton"
                  "{border:1px;border-radius:24px;background-color:#373737;}"
                  "QPushButton:Hover"
                  "{border:1px;border-radius:24px;background-color:#5F5F5F;}"
                  "QPushButton:Pressed"
                  "{border:1px;border-radius:24px;background-coloe:#414141;}");
}

void LevitationButton::setIcon(QString iconName)
{
    m_icon->setPixmap(QPixmap(iconName));
}
void LevitationButton::setText(QString text)
{
    m_text->setText(text);
}
